<%--
  Created by IntelliJ IDEA.
  User: hanfei
  Date: 18/10/20
  Time: 上午11:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>绑定会员</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${allServerPath}static/css/frozenui/frozen.css">
    <style>
        .header-color {
            background-color: #ffffff;
        }

        .try-info {
            margin-top: 15px;
            border-top: none;
        }

    </style>
</head>
<body>
<header class="ui-header ui-border-b header-color">
    <h1>绑定会员信息</h1>
</header>
<div class="ui-footer ui-footer-stable ui-btn-group ui-border-t">
    <button id="submitBtn" class="ui-btn-lg ui-btn-danger">
        提交
    </button>
</div>
<div class="ui-form try-info" style="margin-top: 45px;">
    <form id="userForm" action="${allServerPath}oauth2/bindUser.htmls" method="post">
        <div class="ui-form-item ui-border-b">
            <label>
                用户名<span style="color: red">*</span>
            </label>
            <input type="text" placeholder="用户名" name="studentName" style="height: 44px;">
        </div>
        <div class="ui-form-item ui-border-b">
            <label>
                密码<span style="color: red">*</span>
            </label>
            <input type="password" placeholder="密码" name="password" style="height: 44px;">
        </div>
        <input type="hidden" name="openid" value="${openid}">
    </form>
</div>

<section class="ui-container ui-center">
</section>
<script type='text/javascript' src='${allServerPath}static/js/lib/zepto/zepto.min.js'></script>
<script type='text/javascript' src="${allServerPath}static/js/frozenui/frozen.js"></script>
<script>
    $(function () {
        $("#submitBtn").click(function () {
            var studentName = $("input[name='studentName']").val();
            var password = $("input[name='password']").val();
            if ($.trim(studentName) == "") {
                $.tips({
                    content: '用户名不能为空.',
                    stayTime: 2000,
                    type: "warn"
                });
                return false;
            }
            if ($.trim(password) == "") {
                $.tips({
                    content: '密码不能为空.',
                    stayTime: 2000,
                    type: "warn"
                });
                return false;
            }
            bindMember();
        });
    });


    function bindMember() {
        var openid = $("input[name='openid']").val();
        var studentName = $("input[name='studentName']").val();
        var password = $("input[name='password']").val();
        var url = "${allServerPath}oauth2/bindUser.htmls";
        $.ajax({
            url: url,
            type: 'post',
            data: {
                'openid': openid,
                'ucode': studentName,
                'upasword': password
            },
            dataType: 'json',
            success: function (ret) {
                $.tips({
                    content: ret.message,
                    stayTime: 2000,
                    type: "warn"
                });
            },
            error: function () {
                $.tips({
                    content: '绑定会员失败.',
                    stayTime: 2000,
                    type: "warn"
                });
            }
        });
    }
</script>
</body>
</html>
